package com.xgh.boss;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName Jiaoji
 * @Description
 * @Author xinggh
 * @Date 2020/8/13 23:32
 * @Version 1.0
 **/
public class Jiaoji {

    public static int[] getJiaoji(int[] a, int[] b) {
        if (a.length == 0 || b.length == 0) {
            return new int[0];
        }

        List<Integer> result = new ArrayList<>();
        int al = 0;
        int bl = 0;

        while (al < a.length && bl < b.length) {
            if (a[al] == b[bl]) {
                result.add(a[al]);
                al++;
                bl++;
                continue;
            }

            if (a[al] > b[bl]) {
                bl++;

            } else {
                al++;
            }
        }

        return result.stream().mapToInt(Integer::valueOf).toArray();
    }

    public static void main(String[] args) {
        int a[] = new int[]{1, 3, 4, 5};
        int b[] = new int[]{1, 4, 5};
        int[] r = getJiaoji(a, b);
        System.out.println();
    }
}
